import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:news_flutter/models/video_model.dart';
import 'package:news_flutter/pages/video/video_detail_page.dart';
import 'package:news_flutter/utils/my_navigator.dart';
import 'package:news_flutter/utils/precompile.dart';
import 'package:news_flutter/widgets/custom/cache_image_widget.dart';
import 'package:news_flutter/extension/num_ext.dart';

class VideoItem extends StatefulWidget {
  final VideoModel videoModel;

  const VideoItem({Key key, this.videoModel}) : super(key: key);

  @override
  _VideoItemState createState() => _VideoItemState();
}

class _VideoItemState extends State<VideoItem> {
  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    return InkWell(
      onTap: (){
        MyNavigator.push(context, VideoDetailPage(videoModel: widget.videoModel,),fullscreenDialog: true);
      },
      child: Container(
        width: size.width,
        height: size.width * 0.618,
        child: Column(
          children: <Widget>[
            //视频
            Expanded(
              child: Stack(
                children: <Widget>[
                  //封面图
                  Positioned(
                    left: 0,right: 0,top: 0,bottom: 0,
                    child:MyCacheImage(
                      url: widget.videoModel.coverurl,
                      fit: BoxFit.fitWidth,
                      alignment: Alignment.topCenter,
                    ),
                  ),
                  //标题
                  Container(
                    padding: EdgeInsets.symmetric(horizontal: 10,vertical: 4),
                    decoration: BoxDecoration(
                      color: Colors.black.withOpacity(0.3),
                      borderRadius: BorderRadius.all(Radius.circular(2)),
                    ),
                    child: Text("${widget.videoModel.title}",style: TextStyle(color: Colors.white,fontSize: 16,fontWeight: FontWeight.bold),),
                  ),
                  //播放按钮
                  Center(
                    child: Icon(Icons.play_circle_filled,color: Colors.white.withOpacity(0.7),size: 88,),
                  ),
                  //时常
                  Positioned(
                    right: 0,bottom: 0,
                    child: Container(
                      padding: EdgeInsets.symmetric(horizontal: 10,vertical: 4),
                      decoration: BoxDecoration(
                        color: Colors.black.withOpacity(0.3),
                        borderRadius: BorderRadius.all(Radius.circular(2)),
                      ),
                      child: Text("${widget.videoModel.duration.milliSecondToMinuteAndSecondDes()}",style: TextStyle(color: Colors.white,fontSize: 14),),
                    ),
                  ),
                ],
              ),
            ),
            //作者、播放次数等信息
            Container(
              height: 50,
              child: Row(
                children: <Widget>[
                  //头像
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 10,horizontal: 10),
                    child: ClipOval(
                      child: MyCacheImage(
                        url: widget.videoModel.avatar,
                      ),
                    ),
                  ),
                  //作者名称
                  Container(
                    child: Text(widget.videoModel.author??"",style: TextStyle(color: MyColor.TEXT_GRAY),),
                  ),
                  Expanded(
                    child: Container(),
                  ),
                  //播放次数
                  Container(
                    margin: EdgeInsets.only(right: 10),
                    child: Text("${widget.videoModel.hotindex.friendlyNumWanDes()}",style: TextStyle(color: MyColor.TEXT_GRAY,fontSize: 13),),
                  ),

                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
